<template>
  <transition name="fade">
    <div class="food" v-show="showFlag" ref="foodScroll">
      <div class="food-content">
        <div class="food-img">
          <img :src="food.image">
          <div class="back" @click="back">
            <i class="icon-arrow_lift"></i>
          </div>
        </div>
        <div class="content">
          <div class="name">{{food.name}}</div>
          <div class="count">月售{{food.sellCount}}份&nbsp;&nbsp;&nbsp;&nbsp;好评率{{food.rating}}%</div>
          <div class="price">
            <span class="new">￥{{food.price}}</span>
            <span v-show="food.oldPrice" class="old">￥{{food.oldPrice}}</span>
          </div>
          <div class="cart-control">
            <v-cartcontrol :food="food" ></v-cartcontrol>
          </div>
          <transition name="fade">
            <div @click.stop.prevent="addFood" class="buy" v-show="!food.count || food.count === 0">加入购物车</div>
          </transition>
        </div>
        <split></split>
        <div class="food-introduction" v-show="food.info">
          <h1 class="title">商品介绍</h1>
          <p class="text">{{food.info}}</p>
        </div>
        <split></split>
        <div class="foodRating">
          <h1 class="title">商品评价</h1>
          <ratingSelect :ratings="food.ratings"></ratingSelect>
        </div>
      </div>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
  import BScroll from 'better-scroll'
  import Vue from 'vue'
  import cartcontrol from "../../components/cartcontrol/cartcontrol"
  import ratingSelect from "../../components/ratingSelect/ratingSelect"
  import split from "../../components/split/split"

  export default {
    name: "food",
    props: {
      food: {
        type: Object
      },
    },
    components: {
      'v-cartcontrol':cartcontrol,
      split,
      ratingSelect
    },
    mounted(){
     console.log(this.food)
    },
    data() {
      return {
        showFlag: false,
        myFood:[]
      }
    },
    methods: {
      show() {
        this.showFlag = true
        this.$nextTick(() => {
          if (!this.scoll) {
            this.scroll = new BScroll(this.$refs.foodScroll, {
              click: true
            })
          } else {
            this.scroll.refresh()
          }
        })
      },
      back() {
        this.showFlag = false
      },
      addFood(event) {
        if (!event._constructed) {
          return;
        }
        Vue.set(this.food, 'count', 1)
      }
    },
    // mounted(){
    //   this.myFood = this.food
    // }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .food
    position fixed
    top: 0
    left: 0
    bottom 48px
    width 100%
    height 100%
    z-index 3
    overflow hidden
    background-color #fff
    &.fade-enter-active, &.fade-leave-active
      transition all 0.4s linear
    &.fade-enter, &.fade-leave
      opacity: 0
    .food-content
      .food-img
        position relative
        width: 100%
        height 0
        padding-top 100%
        background-color pink
        img
          position absolute
          left: 0
          top 0
          width 100%
          height 100%
        .back
          position absolute
          top: 10px
          left: 5px
          .icon-arrow_lift
            padding 10px
            font-size 10px
            color: #fff

      .content
        padding: 18px
        position relative
        .name
          font-size: 14px
          font-weight 700
          color rgb(7, 17, 27)
          line-height 14px
        .count
          font-size 10px
          color rgb(147, 153, 159)
          margin 8px 0 18px
        .price
          font-weight 700
          line-height 24px
          .new
            font-size 14px
            color: rgb(240, 20, 20)
          .old
            font-size 10px
            color rgb(147, 153, 159)
        .cart-control
          position absolute
          bottom: 16px
          right: 16px
        .buy
          position absolute
          bottom: 18px
          right: 18px
          border-radius 24px
          background-color rgb(0, 160, 220)
          text-align center
          padding 10px 10px
          color: #fff
          &.fade-enter-active, &.fade-leave-active
            transition all 0.2s
          &.fade-enter, &.fade-leave
            opacity 0

      .food-introduction
        padding 18px
        .title
          font-size 14px
          font-weight 700
          margin-bottom 6px
        .text
          font-size 12px
          font-weight 200
          color rgb(77, 85, 93)
          line-height 24px

      .foodRating
        padding-top 18px
        padding-bottom 50px
        .title
          margin-left 18px
          font-size 16px
          font-weight 700


</style>
